﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LevelManager : MonoBehaviour {
    public List<LevelInfo> levelInfos = new List<LevelInfo>();
    public LevelInfo currLevel = null;
    public List<GameObject> GetCurrLevelEnemys
    {
        get {
            if (currLevel!=null)
            {
                return currLevel.enemys;
            }
            return null;
            }
    }
    public string GetCurrLevelName
    {
        get
        {
            if (currLevel!=null)
            {
                return currLevel.LevelTitle;
            }
            return "";
        }
    }
    public int GetCurrLevelEnemyCount
    {
        get
        {
            if (currLevel!=null)
            {
                return currLevel.enemys.Count;
            }
            return 0;
        }
    }
    int index = 0;
    public Action<LevelInfo> changeLevel;
    public static LevelManager Instance;
    private void Awake()
    {
        Instance = this;
        
    }
    void Start(){
    }
    public void StartLevel()
    {
        if (levelInfos.Count==0)
        {
            return;
        }
        currLevel = levelInfos[index];
        if (changeLevel!=null)
        {
            changeLevel(currLevel);
        }
    
    }

    public void ReStartLevel()
    {
        if (levelInfos.Count == 0)
        {
            return;
        }
        index = 0;
        currLevel = levelInfos[index];
        if (changeLevel != null)
        {
            changeLevel(currLevel);
        }
    }

    public void DelayEnterNextLevel(float time)
    {
        Invoke("EnterNextLevel", time);
    }

    public void EnterNextLevel()
    {
        if (levelInfos.Count == 0)
        {
            return;
        }
        index++;
        index %= levelInfos.Count;
        currLevel = levelInfos[index];
        if (changeLevel != null)
        {
            changeLevel(currLevel);
        }
    }
}
